<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-10-03 16:41:59
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" 
-->
<template>
	<sc-VxeTable ref="xGrid1" :gridEvts="gridEvents" :tablecode="'market_customer_balance'" :gridOps="gridOps"
		:url="this.$API.basedata.businessCompany.list" :params="{ finance_id: 1 }">
	</sc-VxeTable>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false">
	</save-dialog>
	<save-name v-if="dialog.savename" ref="saveName" @success="handleSuccess" @closed="dialog.savename = false">
	</save-name>
	<save-collection v-if="dialog.collection" ref="Collection" @success="handleSuccess" @closed="dialog.collection = false">
	</save-collection>
	<browser v-if="dialog.browser" ref="browserDialog" :title="title" :params="browserparems" :urlParams="urlParams"
		@closed="dialog.browser = false"></browser>
</template>
<script>
// import { useRouter } from "vue-router";
// import { VXETable } from 'vxe-table';
import { ElNotification } from "element-plus";
import SaveDialog from "./save";
import SaveName from "./savename";
import saveCollection from "./savecollection";
import browser from "./browser";
export default {
	components: {
		SaveDialog,
		SaveName,
		saveCollection,
		browser
	},
	name: "market_customer_balance",
	data() {
		return {
			dialog: {
				save: false,
				savename: false,
				collection: false,
				browser: false
			},
			urlParams: {},
			title: "",
			browserparems: {},
			gridEvents: {
				cellDblclick: ({ row }) => {
					this.edit(row);
				},
				add: ({ button }) => {
					this.openSave(button.selectRecords[0]);
				},
				edit: ({ button }) => {
					this.openCollection(button.selectRecords[0]);
				},
				editname: ({ button }) => {
					this.openSaveName(button.selectRecords[0]);
				},
				browser: ({ button }) => {

					let data = button.selectRecords[0];

					this.title = "[" + data.name + "]-科目明细账";
					this.browserparems = {
						company_id: { type: "eq", value: data.id, },
						subject_id: { type: "in", value: ['1122', '2202'] },
					};
					this.urlParams = {
						params: {
							direct: data.direct_id,
						},
					};
					this.dialog.browser = true;
					this.$nextTick(() => {
						this.$refs.browserDialog.open();
					});
				},
			},
			gridOps: {},
		};
	},
	methods: {
		openSave: function (data) {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open().setData(data);
			});
		},
		openSaveName: function (data) {
			this.dialog.savename = true;
			this.$nextTick(() => {
				this.$refs.saveName.open().setData(data);
			});
		},
		openCollection: function (data) {
			this.dialog.collection = true;
			this.$nextTick(() => {
				this.$refs.Collection.open().setData(data);
			});
		},
		handleSuccess() {
			this.$refs.xGrid1.refresh();
		},

		edit(item) {
			let selected = {};
			if (typeof item == "undefined") {
				let selects = this.$refs.xGrid1.xGrid.getCheckboxRecords();
				if (selects.length == 0) {
					this.$message.error("必须选中元素");
					return;
				} else {
					selected = selects[0];
				}
			} else selected = item;
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(selected);
			});
		},
		async del() {
			let selected = this.$refs.xGrid1.xGrid.getCheckboxRecords();
			if (selected.length == 0) {
				ElNotification.error({
					title: "错误",
					message: "必须选中元素",
				});
				return;
			}
			let ids = [];
			selected.forEach((element) => {
				ids.push(element.id);
			});
			var res = await this.$API.basedata.businessCompany.delete.post({
				ids: ids,
			});
			this.isSaveing = false;
			if (res.code == 200) {
				this.$emit("success", this.form, this.mode);
				this.visible = false;
				this.$refs.xGrid1.refresh();
				this.$message.success("操作成功");
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
		},
	},
};
</script>
